package com.sff.easyexcel.test.demo.util;

import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

public class DateUtil {

    public static final String yyyyMMdd = "yyyyMMdd";

    /**
     * 两个日期之间的所有日期的集合
     */
    public static List<Integer> getBetweenDateKey(Long startTime, Long endTime) {

        List<Integer> dateList = new ArrayList<>();
        if (startTime == null || endTime == null) {
            return dateList;
        }

        LocalDate startLocalDate = Instant.ofEpochSecond(startTime).atZone(ZoneId.systemDefault()).toLocalDate();
        LocalDate endLocalDate = Instant.ofEpochSecond(endTime).atZone(ZoneId.systemDefault()).toLocalDate();

        long length = endLocalDate.toEpochDay() - startLocalDate.toEpochDay();
        for (long i = length; i >= 0; i--) {
            String format = endLocalDate.minusDays(i).format(DateTimeFormatter.ofPattern(DateUtil.yyyyMMdd));
            dateList.add(Integer.valueOf(format.substring(6, 8)));
        }

        return dateList;
    }

}
